import { getTopCategoryAPI } from '../../../apis/category'
import { onMounted, ref } from 'vue'
import { useRoute } from 'vue-router'

import { onBeforeRouteUpdate } from 'vue-router'
export function useCategory() {
  //处理分类的数据
const categoryList = ref({})
const route = useRoute()
const getCate = async (id = route.params.id) => {
  const res = await getTopCategoryAPI(id)
  categoryList.value = res.data.result
}
//切换组件，发送分类数据
onBeforeRouteUpdate((to) => {
  console.log(to);
  getCate(to.params.id)

})

onMounted(async () => {
  await getCate();
})
return {
  categoryList
}
}